from selenium import webdriver
from selenium.webdriver.common.by import By
import time

driver = webdriver.Chrome()
driver.get('https://www.baidu.com')

kw = driver.find_element(By.ID, 'kw')
# 输入内容
kw.send_keys("python自动化")
time.sleep(2)
# 清除内容
kw.clear()

# 获取属性值
print(kw.get_attribute('outerHTML'))
print(kw.get_attribute('name'))
print(kw.get_attribute('class'))

# 判断元素是否可见 (返回布尔值)
input = driver.find_element(By.XPATH, '//form[@id="form"]/input[2]')
print(input.is_displayed())
print(kw.is_displayed())

print('-'*100)
# 判断元素是否可用
driver.get('https://sahitest.com/demo/clicks.htm')
disable_ele = driver.find_element(By.XPATH, '//input[@value="disable1"]')
print(disable_ele.is_enabled())
t2 = driver.find_element(By.NAME, 't2')
print(t2.is_enabled())

time.sleep(2)
driver.quit()